#include "bsp_spi.h"

extern SPI_HandleTypeDef hspi2;

uint8_t Bsp_SPI_CS(uint8_t cs)
{
	if(cs)
		HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_RESET);
	else
		HAL_GPIO_WritePin(SPI2_CS_GPIO_Port,SPI2_CS_Pin,GPIO_PIN_SET);
	return 0;
}

uint8_t Bsp_SPI_SYNC(uint8_t sync)
{
	if(sync)
		HAL_GPIO_WritePin(SYNC_GPIO_Port,SYNC_Pin,GPIO_PIN_SET);
	else
		HAL_GPIO_WritePin(SYNC_GPIO_Port,SYNC_Pin,GPIO_PIN_RESET);
	return 0;
}


uint8_t Bsp_SPI_Write(uint8_t *buf,uint16_t length)
{
	return HAL_SPI_Transmit(&hspi2,buf,length,0xffff);
}


uint8_t Bsp_SPI_Read(uint8_t *buf,uint16_t length)
{
	//memset(buf,0,length);
	return HAL_SPI_Receive(&hspi2,buf,length,0xffff);
}

uint8_t Bsp_SPI_WriteRead(uint8_t *write_buf,uint8_t *read_buf,uint16_t length)
{
	return HAL_SPI_TransmitReceive(&hspi2,write_buf,read_buf,length,0xffffff);
}




